﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>被选中的复选框求和</title>
    <script language="javascript">
        function dataCal(){
            let sum = 0;
            let obj = document.getElementsByName("items");
            for(let i = 0;i<obj.length;i++){
                if(!obj[i].checked){
                    continue;
                }   
                sum += parseFloat(obj[i].value);
            }
            alert(sum);
        }
    </script>
</head>
<body>
<input type="checkbox" value="11" name="items">11<br/>
<input type="checkbox" value="22" name="items">22<br/>
<input type="checkbox" value="33" name="items">33<br/>
<input type="checkbox" value="44" name="items">44<br/>
<input type="button" value="求和" onclick="dataCal()">
</body>
</html>